package com.szrt.cll.test.school.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.szrt.cll.test.core.base.BaseController;
import com.szrt.cll.test.core.base.BaseService;
import com.szrt.cll.test.dto.SelectionDTO;
import com.szrt.cll.test.school.entity.SchoolEntity;
import com.szrt.cll.test.school.service.SchoolService;

@Controller
@RequestMapping("/school")
public class SchoolController extends BaseController<SchoolEntity>{

	@Autowired
	private SchoolService service;
	
	@Override
	public BaseService<SchoolEntity> getBaseService() {
		
		return service;
	}
	
	@ResponseBody
	@RequestMapping("/findAllSelectionDTO")
	public List<SelectionDTO> findAllSelectionDTO(){
		return service.findAllSelectionDTO();
	}
	
	
	@ResponseBody
	@RequestMapping("/findByName")
	public Map<String,Object> findByName(Integer page, Integer rows,String name){
		System.err.println("进入findByName方法....");
		if(null == page){
			page=1;
		}
		if(null == rows){
			rows = 10;
		}
		Integer before = (page -1)*rows;
		Integer after = rows;
		
		Map<String,Object> pageMap = new HashMap<String,Object>();
		pageMap.put("before", before);
		pageMap.put("after", after);
		
		if(null != name && !"".equals(name.trim())){
			pageMap.put("name", name+"%");
		}
		
		
		List<SchoolEntity> list= service.findByName(pageMap);
		Map<String,Object> map=new HashMap<>();
		
		map.put("rows",list);
		map.put("result","success");
		
		return map;
	}
	
}
